<template>
  <div>
    <ul>
      <li v-for="(item, index) in arr" :key="index">
        {{ item }}
      </li>
    </ul>
    <button @click="revBtn">数组翻转</button>
    <button @click="sliceBtn">截取前3个</button>
    <button @click="updateBtn">更新第一个元素值</button>
    <button @click="guoying">强制更新</button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      arr: [1, 5, 8, 9, 3],
    };
  },
  methods: {
    revBtn() {
      this.arr.reverse();
    },
    sliceBtn() {
      this.arr = this.arr.slice(0, 3);
      // this.arr = newArr;
    },
    updateBtn() {
      this.$set(this.arr, 0, 100);
    },
    guoying() {
      this.arr[0] = "王大队长";
      //$forceUpdate()实现强制更新
      this.$forceUpdate();
    },
  },
};
</script>

<style>
</style>